package com.xbongbong.pro.rabbitmq.consumer;

import com.alibaba.fastjson.JSON;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.pojo.dto.MessageRabbitMqDTO;
import com.xbongbong.pro.message.pojo.vo.MessageRabbitMqVO;
import com.xbongbong.pro.rabbitmq.binders.DataCenterConsumerBinder;
import com.xbongbong.pro.rabbitmq.constant.DataCenterBinderConstant;
import com.xbongbong.pro.rabbitmq.feign.CrmFeignClient;
import com.xbongbong.pro.rabbitmq.feign.DataCenterFeignClient;
import feign.RetryableException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.Header;

import javax.annotation.Resource;

/**
 * @ClassName DwListener
 * @Description dw 消息消费者
 * @Author mengna.Deng
 * @Date 2021/5/6 17:06
 * @Version 1.0
 */
@EnableBinding(DataCenterConsumerBinder.class)
public class DataCenterListener {
    private static Logger logger = LoggerFactory.getLogger(DataCenterListener.class);

    @Resource
    private DataCenterFeignClient dataCenterFeignClient;

    @StreamListener(value = DataCenterBinderConstant.DATA_WARNING_INPUT)
    public void dataWarningReceive(MessageRabbitMqDTO message) {
        XbbResponse<MessageRabbitMqVO> response = null;
        try {
            response = dataCenterFeignClient.dataWarningAdd(message);
            logger.info("Received: "  + "dataWarning " + "\n message=" + JSON.toJSONString(message));
        } catch (RetryableException e) {
            logger.error("DataCenterListener.dataWarningReceive RetryableException case by Read timed out" );
        } catch (Exception e) {
            logger.error("DataCenterListener.dataWarningReceive Exception", e);
        }
    }

}
